<?php

namespace iBrand\Shop\Core\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Passport\HasApiTokens;


class Clerk extends Authenticatable
{
    use HasApiTokens;
    use Notifiable;

    protected $guarded = ['id'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);

        $prefix = config('ibrand.app.database.prefix', 'ibrand_');

        $this->setTable($prefix . 'o2o_clerk');
    }

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function shops()
    {
        return $this->belongsTo(Shop::class, 'shop_id');
    }


    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = bcrypt($value);
    }

    public function getAvatarUrlAttribute()
    {
        if ($this->avatar !== null) {
            return url($this->avatar);
        }
        return '';
    }


    public function shopOrder()
    {
        return $this->hasMany(ShopOrder::class, 'clerk_id', 'id');
    }


}